package com.yang.controller;

import com.github.pagehelper.PageInfo;
import com.yang.common.PageQuery;
import com.yang.common.ResponseResult;
import com.yang.entity.dto.ConsultationRecordDTO;
import com.yang.entity.vo.ConsultationRecordVO;
import com.yang.entity.vo.ConsultationRecordDetailVO;
import com.yang.service.ConsultationRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultation-record")
@Api(tags = "病人就诊记录相关接口", value = "病人就诊记录相关接口")
@Slf4j
public class ConsultationRecordController {

    @Autowired
    private ConsultationRecordService consultationRecordService;

    @PostMapping("/pageQuery")
    @ApiOperation(value = "分页查询病人就诊记录")
    public ResponseResult<PageInfo<ConsultationRecordVO>> pageQuery(@RequestBody PageQuery<ConsultationRecordDTO> pageQuery) {
        PageInfo<ConsultationRecordVO> result = consultationRecordService.pageQuery(pageQuery);
        return ResponseResult.success(result);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增病人就诊记录")
    public ResponseResult<Integer> add(@RequestBody ConsultationRecordDTO consultationDetailDTO) {
        int result = consultationRecordService.add(consultationDetailDTO);
        if (result == 1) {
            return ResponseResult.success(result);
        }
        return ResponseResult.fail("新增病人就诊记录失败");
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新病人就诊记录")
    public ResponseResult<Integer> update(@RequestBody ConsultationRecordDTO consultationDetailDTO) {
        int result = consultationRecordService.update(consultationDetailDTO);
        if (result == 1) {
            return ResponseResult.success(result);
        }
        return ResponseResult.fail("更新病人就诊记录失败");
    }

    @GetMapping("/getConsultationRecordDetail")
    @ApiOperation(value = "查询病人就诊记录详情")
    public ResponseResult<List<ConsultationRecordDetailVO>> getConsultationRecordDetail(String consultationId) {
        List<ConsultationRecordDetailVO> result = consultationRecordService.getConsultationRecordDetail(consultationId);
        return ResponseResult.success(result);
    }

}
